﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using SMS.Entities.BaseClasses;
using SMS.Common.Silverlight;
using System.Windows.Printing;

namespace SMS.ViewModel.Purchase
{
    public class BarcodePrintViewModel:BaseNotify
    {
        WrapPanel objWrapPanel;
        public BarcodePrintViewModel(int Quantity,int StockWiseID,WrapPanel objWrapPanel)
        {
            this.objWrapPanel = objWrapPanel;
            CreateBarcode(Quantity, StockWiseID);
            PrintCommand = new DelegateCommand(Print, null);
        }

        private void CreateBarcode(int Quantity, int StockWiseID)
        {
            for (int i = 0; i < Quantity; i++)
            {
                Views.Purchase.BarcodeItem item = new Views.Purchase.BarcodeItem();
                item.tb_barcodeValue.Text = Convert.ToString(StockWiseID.ToString().PadLeft(10,'0'));
                objWrapPanel.Children.Add(item);
            }
        }

        public ICommand PrintCommand { get; set; }
        private void Print(object param)
        {
            PrintDocument document = new PrintDocument();
            document.PrintPage += (s, e) =>
            {
                e.PageVisual = this.objWrapPanel;
            };
            document.Print("Printing Borcodes..");
        }
    }
}
